from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.writer.excel import ExcelWriter
import os.path

dir_path = os.path.join(".", "file")
file_path = os.path.join(dir_path, "333.xlsx")
wb = load_workbook(file_path)
# 获取所有表名
sheetnames = wb.sheetnames
# 取第1张表
ws = wb[sheetnames[0]]

sheet = wb.active
a = sheet.max_row

new_path = os.path.join(dir_path, "444.xlsx")
wb_new = load_workbook(new_path)
sheetnames_new = wb_new.sheetnames
ws_new = wb_new[sheetnames_new[0]]

i = 0
while i < a:
    i = i + 1
    ws_new.cell(i, 1).value = ws.cell(i, 1).value
    if ws.cell(i, 2).value == '题目':
        ws_new.cell(i, 2).value = ws.cell(i, 2).value
    else:
        arr = str(ws.cell(i, 2).value).split('\n')
        for j in range(arr.__len__()):
            ws_new.cell(i, j + 2).value = str('%s >>>> %s' % (arr[j], ws.cell(i, 3).value[j]))

wb_new.save(new_path)
